//
//  AEPointsSingleSignView.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/17.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEPointsSingleSignView.h"
#import "AESignInfosModel.h"

@interface AEPointsSingleSignView ()
@property (nonatomic, strong) AESignInfosModel *model;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIImageView *cntImgView;

@property (nonatomic, strong) UILabel *cntLabel;

@property (nonatomic, strong) UIView *selectedView;

/// 已签到背景图
@property (nonatomic, strong) UIImageView *signedInView;

@end

@implementation AEPointsSingleSignView

- (void)initWithSubView {
    self.backgroundColor = kWhiteColor;
    self.layer.borderColor = [UIColor colorWithHexString:@"7c4df7"].CGColor;
    self.layer.borderWidth = 1;
    self.layer.cornerRadius = 10;
    self.layer.masksToBounds = YES;
    
//    [self initWithSelectedView];
}

- (void)initWithSelectedView {
    if (!_selectedView) {
        CGRect frame = self.bounds;
        _selectedView = [[UIView alloc] initWithFrame:frame];
        _selectedView.backgroundColor = [UIColor colorWithHexString:@"#c6b0ff"];
        _selectedView.alpha = 0.5;
        [self addSubview:_selectedView];
        _selectedView.hidden = YES;
    }
}

- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(5, 3.5, self.width - 10, 14);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:10 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#8050F7"];
            label.textAlignment = NSTextAlignmentCenter;
        }];
    }
    if (self.model) {
        self.titleLabel.text = [NSString stringWithFormat:@"- %@ -", self.model.name];
    }
}

- (void)initWithCntImgView {
    if (!_cntImgView) {
        UIImage *image = [UIImage imageNamed:@"ic_points_acquire_cnt_small"];
        CGRect frame = CGRectMake((self.width - image.size.width) * 0.5, (self.height - image.size.height) * 0.5, image.size.width, image.size.height);
        _cntImgView = [UIImageView createWithImageView:self frame:frame defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
            
        }];
    }
}

- (void)initWithCntLabel {
    if (!_cntLabel) {
        CGRect frame = CGRectMake(8, self.height - 4 - 10.8, self.width - 8 * 2, 10.8);
        _cntLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:6.5 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
            label.backgroundColor = [UIColor colorWithHexString:@"#7C4DF7"];
            label.textColor = kWhiteColor;
            label.textAlignment = NSTextAlignmentCenter;
            label.layer.cornerRadius = frame.size.height * 0.5;
            label.layer.masksToBounds = YES;
        }];
    }
    if (self.model) {
        self.cntLabel.text = objectNull(self.model.remarks);
    }
}

- (void)initWithSignedInView {
    if (!_signedInView) {
        UIImage *image = [UIImage imageNamed:@"ic_signed_in_bg"];
        CGRect frame = self.bounds;
        _signedInView = [UIImageView createWithImageView:self frame:frame defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
            imageView.hidden = YES;
        }];
    }
}

- (void)updateWithViewData:(id)data {
    self.model = data;
    
    [self initWithTitleLabel];
    
    [self initWithCntImgView];
    
    [self initWithCntLabel];
    
    [self initWithSignedInView];
    
    if (self.model.isSign) {
        self.titleLabel.textColor = kWhiteColor;
        self.signedInView.hidden = NO;
        [self bringSubviewToFront:self.signedInView];
        [self bringSubviewToFront:self.titleLabel];
        [self bringSubviewToFront:self.cntLabel];
    } else {
        self.titleLabel.textColor = [UIColor colorWithHexString:@"#8050F7"];
        self.signedInView.hidden = YES;
    }
    
}

@end
